package com.zhida.smartcontrol.pagectrl.devicedetail.autotime;

import com.alibaba.fastjson.JSON;
import com.yanzhenjie.kalle.Params;
import com.zhida.smartcontrol.common.Api;
import com.zhida.smartcontrol.knet.KalleCallBack;
import com.zhida.smartcontrol.mvp.BasePresenterImpl;

import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.List;

/**
 * author: tanjianpei
 * date: 2019/10/17 017 13:07
 * description:
 */

public class AutoTimePresenter extends BasePresenterImpl<AutoTimeContract.View> implements AutoTimeContract.Presenter {

    @Override
    public void inidData() {
        List<String> tabs = Arrays.asList(new String[]{"周一", "周二", "周三", "周四", "周五", "周六", "周日"});
        mView.inflateTab(tabs);
    }

    @Override
    public void requestTime(String id, int weekId) {
        Params params = Params.newBuilder()
                .add("lampSwitchId", id)
                .add("weekday", weekId + "")
                .build();
        mKalleCenter.get(Api.FIND_WAY_DATA, params,true, new KalleCallBack() {
            @Override
            public void onSuccess(String result, String msg) {
                List<AutoTimeBean> timeList = JSON.parseArray(result, AutoTimeBean.class);
                mView.showTimeList(timeList);
            }

            @Override
            public void onFailed(String msg) {
                mView.showMsg(msg);
            }
        });
    }
}
